package com.atguigu.gmall.controller;

import com.atguigu.gmall.product.client.ProductFeignClient;
import com.atguigu.gmall.product.model.SkuInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @author: atguigu
 * @create: 2023-05-05 11:34
 */
@Controller
@SuppressWarnings("all")
public class CartController {

    @Autowired
    private ProductFeignClient productFeignClient;

    /**
     * 加入购物车成功页面渲染
     *
     * @param skuId
     * @param skuNum
     * @return
     */
    @GetMapping("/addCart.html")
    public String addCartSuccess(Model model, @RequestParam("skuId") Long skuId, @RequestParam("skuNum") Integer skuNum) {
        SkuInfo skuInfo = productFeignClient.getSkuInfo(skuId);
        model.addAttribute("skuInfo", skuInfo);
        model.addAttribute("skuNum", skuNum);
        return "/cart/addCart";

    }

    /**
     * 渲染购物车列表页面
     * @return
     */
    @GetMapping("/cart.html")
    public String cartHtml() {
        return "/cart/index";
    }
}
